<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .light {
            height: 100px;
            width: 100px;
            border-radius: 50%;
        }
        .nolight {
            background-color: #555;
        }
        .g {
            background-color: green;
        }
        .y {
            background-color: yellow;
        }
        .r {
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="light"></div>
    <div class="light"></div>
    <div class="light"></div>
    <button id="open">开灯</button>
    <script>
        const light = document.getElementsByClassName("light")
        light[0].setAttribute("class", "light g")
    </script>
</body>
</html>